package com.foxzzz.dynamic.programming;

public class Solution264 {
    public int nthUglyNumber(int n) {
        int[] dp = new int[n];
        dp[0] = 1;
        int[] array = new int[]{2, 3, 5};
        for (int i = 1; i < dp.length; i++) {
            int min = Integer.MAX_VALUE;
            for (int j = 0; j < i; j++) {
                for (int k = 0; k < array.length; k++) {
                    long num =dp[j] * array[k];

                    if (num/(array[k]*1.0)==dp[j]&&num - dp[i - 1] > 0) {
                        min = Math.min(min, (int) num);
                    }
                }
            }
            dp[i] = min;
        }

        return dp[n - 1];
    }


    public static void main(String[] args) {
      //  System.out.println(new Solution264().nthUglyNumber(1407));
        System.out.println(new Solution264().nthUglyNumber(1690));
    }
}
